package com.kfm.hotel.config;


import com.kfm.hotel.interceptor.LoginInterceptor;
import com.kfm.hotel.interceptor.RememberMeInterceptor;
import com.kfm.hotel.util.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
@Import(HotelProperties.class)
public class ApplicationConfig extends WebMvcConfigurationSupport {
    @Autowired
     private RememberMeInterceptor rememberMeInterceptor;
    @Value("${hotel.upload-path}")
    private String uploadPath;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 拦截所有请求，除了登录页面和登录接口(拦截器写法1)
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**").excludePathPatterns("/", "/login", "/captcha/**", "/static/**", "/static/images/favicon.ico","/images/**","/email");

        // 拦截登录页面和登录接口（拦截器写法2）
        registry.addInterceptor(rememberMeInterceptor).addPathPatterns("/","/login");
    }
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        //释放文件路径
        registry.addResourceHandler("/images/**").addResourceLocations("file:"+ uploadPath);
    }

}
